<?php

/**
 * GeoForm class.
 * GeoForm is the data structure for sending and retrieving GeoData to Google
 */
class GeoForm extends CFormModel
{
	
	public function visaPrefixList() {
		return  array(	"4539", //Barclays Bank Connect Visa Debit Card
						"4556",
						"4916",
						"4917",
						"4532",
						"4929",
						"40240071",
						"4485",
						"4716",
						"4",
					);
	}
	public function mastercardPrefixList(){ 
		return  array(	"51",
						"52",
						"53",
						"54",
						"55",
					);
	}
	public function amexPrefixList(){ 
		return  array(	"34",
						"37",
					);			
	}
	public function lasercardPrefixList(){ 
		return  array(	"6304",
						"6706",
						"6771",
						"6709",
					);			
	}
/*
	private $discoverPrefixList[] = "6011";

	private $dinersPrefixList[] =  "300";
	private $dinersPrefixList[] =  "301";
	private $dinersPrefixList[] =  "302";
	private $dinersPrefixList[] =  "303";
	private $dinersPrefixList[] =  "36";
	private $dinersPrefixList[] =  "38";

	private $enRoutePrefixList[] =  "2014";
	private $enRoutePrefixList[] =  "2149";

	private $jcbPrefixList16[] =  "3088";
	private $jcbPrefixList16[] =  "3096";
	private $jcbPrefixList16[] =  "3112";
	private $jcbPrefixList16[] =  "3158";
	private $jcbPrefixList16[] =  "3337";
	private $jcbPrefixList16[] =  "3528";

	private $jcbPrefixList15[] = "2100";
	private $jcbPrefixList15[] = "1800";

	private $voyagerPrefixList[] = "8699";
*/
/*
'prefix' is the start of the CC number as a string, any number of digits.
'length' is the length of the CC number to generate. Typically 13 or 16
*/

	private function completed_number($prefix, $length) {

    $ccnumber = $prefix;

    # generate digits

    while ( strlen($ccnumber) < ($length - 1) ) {
        $ccnumber .= rand(0,9);
    }

    # Calculate sum

    $sum = 0;
    $pos = 0;

    $reversedCCnumber = strrev( $ccnumber );

    while ( $pos < $length - 1 ) {

        $odd = $reversedCCnumber[ $pos ] * 2;
        if ( $odd > 9 ) {
            $odd -= 9;
        }

        $sum += $odd;

        if ( $pos != ($length - 2) ) {

            $sum += $reversedCCnumber[ $pos +1 ];
        }
        $pos += 2;
    }

    # Calculate check digit

    $checkdigit = (( floor($sum/10) + 1) * 10 - $sum) % 10;
    $ccnumber .= $checkdigit;

    return $ccnumber;
}

	public function CreditCardNumber($prefixList, $length=16, $howMany=1) {

    	for ($i = 0; $i < $howMany; $i++) {

        	$ccnumber = $prefixList[ array_rand($prefixList) ];
        	$result[] = $this->completed_number($ccnumber, $length);
    	}

    return $result;
	}
	


	/**
	 * Declares the validation rules.
	 * The rules state that username and password are required,
	 * and password needs to be authenticated.
	 */
	public function rules()
	{
		return array(
			// username and password are required
			array('city, street', 'required'),
		);
	}

	/**
	 * Declares attribute labels.
	 */
	public function attributeLabels()
	{
		return array(
			'city'=>'Ort',
			'street'=>'Strasse',
		);
	}
	
}
